var accessTypeData = [{text:"出库",value:"2"},{text:"入库",value:"1"}];
mini.parse();
var grid = mini.get("ReportRepairBarcodeGrid");
grid.load();
var projectName = $("#projectName").val();
var defaultParam = {};

function editReportRepairBarcode(row) {
	if(row){
		openWindowsReportRepairBarcode(row.id,"edit","编辑");
	 }else{
		 row = grid.getSelected();
		if(row){
			openWindowsReportRepairBarcode(row.id,"edit","编辑");
		}else{
			  mini.alert("请选中一条记录");
		}
	} 	
}
function openWindowsReportRepairBarcode(id,openType,WindowName){
	mini.open({
        url: projectName+"/ReportRepairBarcodeAdmin/EditPage",
        title: WindowName, width: 700, height: 500,
        onload: function () {
            var iframe = this.getIFrameEl();
            var data = { action: openType, id: id };
            iframe.contentWindow.CheckEventReportRepairBarcode(data);
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}
function addReportRepairBarcode(){
	openWindowsReportRepairBarcode("","new","新增");
}

function onrowdblclick(e){
	 var record = e.record;
	openWindowsReportRepairBarcode(record.id,"look","查看");
}


function seachRow(){
	 var form = new mini.Form("#formseach");
    var data = form.getData(true, false);
    grid.load(data);
	
}
function resetForm(){
	 var form = new mini.Form("#formseach");
     form.reset();
     form.setData(defaultParam,false);
}
function exportReportRepairBarcode() {
	var rows = grid.getSelecteds();
	var idString = '';
	var url = projectName +"/ReportRepairBarcodeAdmin/exportReportRepairBarcodeExcel?";
    if (rows.length > 0) {
	    var ids = [];
	    for (var i = 0, l = rows.length; i < l; i++) {
	        var r = rows[i];
	        ids.push(r.id);
	    }
	    idString = ids.join(',');    
	    mini.get("ids").setValue(idString);
	    util.exportDataToClient($('#ReportRepairBarcodeListForm'), url);
	} else {
		
		mini.confirm('导出全部？如查询条件不为空，则导出符合查询条件的所有数据.','确定？',function(action) {
			if (action == 'ok') {
				mini.get('ids').setValue('');
				util.exportDataToClient($('#ReportRepairBarcodeListForm'), url);
			} else {
				window.close();
			}
		});
	}
}	

function removeReportRepairBarcode(){
	var rows = grid.getSelecteds();
    if (rows.length > 0) {
    	mini.confirm('确定删除选中记录？','确定？',function(action) {
    		if (action == 'ok') {
                var ids = [];
                for (var i = 0, l = rows.length; i < l; i++) {
                    var r = rows[i];
                    ids.push(r.id);
                }
                var idString = ids.join(',');
                
                $.ajax({
                    url: projectName+"/ReportRepairBarcodeAdmin/batchDelReportRepairBarcode?ids=" +idString,
                    type : 'post',
                    dataType : 'json',
                    success: function (data, textStatus, jqXHR) {
                    	if (data.status == '0' || data.status == '1') {
                    		mini.alert(data.message, '', function() {
    							grid.reload();
    						});
    					} else {
    						mini.alert("发生错误!", '', function() {
    							grid.reload();
    						});
    					}
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                    	mini.alert("发生错误，操作失败！");
                    }
                });
             
    		} else {
    			window.close();
    		}
    	});
    	
    } else {
        mini.alert("请选中一条记录");
    }

}

function importReportRepairBarcode(){
	mini.open({
        url: projectName+"/AttachmentAdmin/importExcelPage?configName=ReportRepairBarcodeEntityExcel&importType=add",
        title: "数据导入", width: 700, height: 500,
        onload: function () {
            var iframe = this.getIFrameEl();
            var data = { action: openType, id: id };
            iframe.contentWindow.CheckEventReportRepairBarcode(data);
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

function setDefaultParam(data){
	defaultParam.equipmentTypeId = data.equipmentTypeId;
	defaultParam.businessId = data.businessId;
	defaultParam.equipmentId = data.equipmentId;
	defaultParam.statusNumId = data.statusNumId;
	defaultParam.attributeNumId = data.attributeNumId;
	defaultParam.updateTime = formatDate(data.updateTime);
	 var form = new mini.Form("#formseach");
     form.setData(defaultParam,false);
	seachRow();
}
function formatDate(now) { 
    var year=now.getFullYear(); 
    var month=setPrefix(now.getMonth()+1); 
    var date=setPrefix(now.getDate()); 
    var hour=setPrefix(now.getHours()); 
    var minute=setPrefix(now.getMinutes()); 
    var second=setPrefix(now.getSeconds()); 
    return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second; 
} 
function setPrefix(d){
	if(parseInt(d/10)==0){
		return "0"+d;
	}else{
		return d;
	}
}
function addDefaultParam(json){
	for(key in defaultParam){
		json[key] = defaultParam[key];
	}
	return json;
}
